<template>
  <div>接受消息:{{message}}</div>
</template>

<script>
import pubsub from "pubsub-js";
export default {
  name: "",
  data() {
    return {
      message:'11'
    };
  },
  created() {

  },
  mounted() {
    let self = this
    this.pubId = pubsub.subscribe("hello", function (msgName,data) {
      // console.log("有人发布了hello消息，hello消息的回调执行了");
      // console.log(msgName,data);
      console.log(self);
      // self.message = data
    });

    //二次封装的
    $bus.on("a",data => {
      console.log(data)
    })

    //手写的发布订阅
    this.$bus.$on("sendTitle",e=>{
      console.log("--->",e)
    })
    this.$bus.$on("sendTitle",e=>{
      console.log("--->",'lalala')
    })

  },
  beforeDestroy() {
    //在组件销毁之前去取消订阅
    pubsub.unsubscribe(this.pubId)
    //二次封装的
    $bus.off("a")
    //手写的发布订阅
    this.$bus.$off("sendTitle",()=>{})

  },
  methods: {

  },
};
</script>

<style scoped>

</style>

